# -*- coding: utf-8 -*-
from selenium.webdriver.support.ui import Select
from selenium.webdriver import ActionChains
from xlutils.copy import copy
import time
import xlrd
from Page.branchuwPage import branchuwPage
class branchuw():
    def __init__(self,driver):
        self.driver=driver
        self.branchuwPage=branchuwPage(self.driver)
    def GrpInsurance(self):
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame("head")
        time.sleep(1)
        self.branchuwPage.groupBtn().click()
    def InquiryManager(self):
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame("fraMenu")
        time.sleep(2)
        self.branchuwPage.btnInquiry().click()
        time.sleep(1)
    def BranchUw(self):
        self.branchuwPage.btnbranchuw().click()
        time.sleep(1)
    # 分公司核保
    def publictopersonal(self,QuotName,BranchUWOpinion,BranchUWConclu):
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame("fraInterface")
        time.sleep(1)
        # 输入客户名称
        self.branchuwPage.inpQuotName().send_keys(QuotName)
        time.sleep(1)
        # 查询
        self.branchuwPage.btnQuery().click()
        time.sleep(1)
        # 选择目标数据
        self.branchuwPage.radTarget().click()
        time.sleep(1)
        # 点击申请
        self.branchuwPage.btnSubmit().click()
        time.sleep(1)
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        self.branchuwPage.butSubmit().click()
        time.sleep(1)
        window2 = self.driver.window_handles
        self.driver.switch_to.window(window2[-1])
        self.driver.switch_to.frame("fraInterface")
        time.sleep(1)
        # 选择数据（个人池）
        self.branchuwPage.radTarget1().click()
        time.sleep(1)
#         进入
        self.branchuwPage.btnGoto().click()
        time.sleep(1)
        self.branchuwPage.inpBranchUWOpinion().send_keys(BranchUWOpinion)
        time.sleep(1)
        self.branchuwPage.btnBranchUWOpinionSaveButton().click()
        time.sleep(1)
        window3 = self.driver.window_handles
        self.driver.switch_to.window(window3[-1])
        self.branchuwPage.butSubmit().click()
        time.sleep(1)
        window4 = self.driver.window_handles
        self.driver.switch_to.window(window4[-1])
        self.driver.switch_to.frame("fraInterface")
        time.sleep(1)
        ActionChains(self.driver).double_click(self.branchuwPage.secBranchUWConclu()).perform()
        time.sleep(1)
        Select(self.branchuwPage.codeselect()).select_by_visible_text(BranchUWConclu)
        time.sleep(1)
        self.branchuwPage.btnBranchUWSubmitButton().click()
        time.sleep(1)
        self.driver.switch_to_alert().accept()
        time.sleep(1)
        window5 = self.driver.window_handles
        self.driver.switch_to.window(window5[-1])
        self.branchuwPage.butSubmit().click()
        time.sleep(1)
    #     完成询价
    def quote(self,FPreCustomerName):
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        self.driver.switch_to.frame("fraMenu")
        time.sleep(1)
        self.branchuwPage.btnInquiryEntry().click()
        time.sleep(1)
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame('fraInterface')
        time.sleep(1)
        self.branchuwPage.inpFPreCustomerName().send_keys(FPreCustomerName)
        time.sleep(1)
        self.branchuwPage.btnQuery2().click()
        time.sleep(1)
        self.branchuwPage.radTarget2().click()
        time.sleep(1)
        self.branchuwPage.btnQuotation().click()
        time.sleep(1)
        window2 = self.driver.window_handles
        self.driver.switch_to.window(window2[-1])
        self.branchuwPage.butSubmit().click()
        time.sleep(1)
    #     选择报价计划
    def CheckQuotPlan(self):
        window=self.driver.window_handles
        self.driver.switch_to.window(window[-1])
        self.driver.switch_to.frame('fraInterface')
        time.sleep(1)
        self.branchuwPage.btnCheckQuotPlan().click()
        time.sleep(1)
        window1=self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame('fraInterface')
        time.sleep(1)
        # self.driver.find_element_by_xpath('//*[@id="checkAllQuotPlanGrid"]').click()
        # time.sleep(1)

        # self.branchuwPage.checkAllQuotPlanGrid().click()
        # time.sleep(1)
        radio=self.branchuwPage.checkAllQuotPlanGrid()
        number=len(radio)
        for j in range(number):
            radio[j].click()
            radio = self.branchuwPage.checkAllQuotPlanGrid()
        self.branchuwPage.btnSelectButton2().click()
        time.sleep(1)
        window = self.driver.window_handles
        self.driver.switch_to.window(window[-1])
        self.branchuwPage.butSubmit().click()
        time.sleep(1)
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame('fraInterface')
        time.sleep(1)
#         关闭
        self.branchuwPage.btnClose().click()
        time.sleep(1)
    #     投保书打印
    def ApplicationPrint(self,preCustomerName):
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        self.driver.switch_to.frame("fraMenu")
        time.sleep(1)
        self.branchuwPage.btnapplicationprint().click()
        time.sleep(1)
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame('fraInterface')
        time.sleep(1)
        self.branchuwPage.inppreCustomerName().send_keys(preCustomerName)
        time.sleep(1)
        self.branchuwPage.btnQuery3().click()
        time.sleep(1)
        self.branchuwPage.radTarget3().click()
        time.sleep(1)
        self.branchuwPage.btnApplicationCreate().click()
        time.sleep(1)
        window = self.driver.window_handles
        self.driver.switch_to.window(window[-1])
        self.branchuwPage.butSubmit().click()
        time.sleep(1)
    def ApplicationNo(self):
        '''取数据'''
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame('fraInterface')
        time.sleep(1)
        applicaitonNo = self.branchuwPage.inpPropInfoGrid1().get_attribute("value")
        print(applicaitonNo)
        No = self.driver.find_element_by_xpath('//*[@id="PropInfoGrid2r0"]').get_attribute("value")
        excelpath = r'C:/Users/tanjm.ext/PycharmProjects/GroupL/TestData/outputdata.xls'
        wtbook = xlrd.open_workbook(excelpath)
        newb = copy(wtbook)
        # sheet = newb.add_sheet('Sheet3')
        sheet = newb.get_sheet(0)
        sheet.write(1, 0, applicaitonNo)
        sheet.write(1, 1, No)
        newb.save(excelpath)































